package com.gc.controller.courseServlet;

import com.gc.entity.Course;
import com.gc.entity.Teacher;
import com.gc.repository.CourseRepository;
import com.gc.repository.TeacherRepository;
import com.gc.repository.impl.CourseRepositoryImpl;
import com.gc.repository.impl.TeacherRepositoryImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "courseFind", value = "/courseFind" )
public class courseFind extends HttpServlet {
    CourseRepository courseRepository = new CourseRepositoryImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<Course> courses = courseRepository.FindAll();
        System.out.println(courses);
        response.getWriter().write(gson.toJson(R.ok().data(courses)));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<Course> courses = courseRepository.FindAll();
        System.out.println(courses);
        response.getWriter().write(gson.toJson(R.ok().data(courses)));
    }
}
